package com.guaoran.interview.spring.event;

import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author : 孤傲然
 * @description : 发送邮件，设置黑名单。当为黑名单时，发送事件
 * @date :2020/1/2 14:00
 */
@Service
public class EmailService implements ApplicationEventPublisherAware {
    private List<String> blackList;
    private ApplicationEventPublisher publisher;
    @Override
    public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
        this.publisher = applicationEventPublisher;
    }
    public void setBlackList(List<String> blackList){
        this.blackList = blackList;
    }
    public void sendEmail(String address,String content){
        if(blackList.contains(address)){
            publisher.publishEvent(new BlackListEvent(this,address,content));
            return;
        }
        System.out.println("sending email");
    }
}
